/**Class represents a rectangle, where all angles have the same value and both parallel edges the same length.
 * 
 */
public class Rectangle implements Polygon, Scalable {
	private double lengthA;
	private double lengthB;
	
	/**Creates a new rectangle where both parallel edges have the same length.
	 * 
	 * @param lengthA Length of the first two parallel edges.
	 * @param lengthB Length of the secont two parallel edges.
	 * @throws ValueSmallerZeroException Exception if negative values are given for the length of an edge.
	 */
	public Rectangle(double lengthA, double lengthB) throws ValueSmallerZeroException {
		if(lengthA > 0) {
			this.lengthA = lengthA;
		} else {
			throw new ValueSmallerZeroException(lengthA);
		}
		if(lengthB > 0) {
			this.lengthB = lengthB;
		} else {
			throw new ValueSmallerZeroException(lengthB);
		}
	}
	
	/**Returns the number of edges.
	 * 
	 * @return Integer value 4 since rectangle has 4 edges.
	 */
	@Override
	public int edges() {
		return 4;
	}

	/**Calculates the size of the area the specified rectangle takes in.
	 * 
	 * @return Calculated double value of area.
	 */
	@Override
	public double area() {
		return this.lengthA*this.lengthB;
	}

	/**Calculates the size of the outline the specified rectangle takes in.
	 * 
	 * @return Calculated double value of the outline.
	 */
	@Override
	public double perimeter() {
		return this.lengthA*2 + this.lengthB*2;
	}

	/**Changes the size of the specified rectangle according to a given factor. 
	 * 
	 * @param factor The value by which the figure will be scaled up or down.
	 * @throws ValueSmallerZeroException Exception if there is a negative value given as scale-factor.
	 */
	@Override
	public void scale(double factor) throws ValueSmallerZeroException {
		if(factor > 0) {
			this.lengthA = lengthA*factor;
			this.lengthB = lengthB*factor;
		} else {
			throw new ValueSmallerZeroException(factor);
		}
	}
	
}
